package com.cnzha.mr.wordcount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


/**
 * @Author: zhaoxin
 * @email: zdkk@foxmail.com
 * @Date: 3/31/2020 11:15 AM
 */
public class WordCountDriver {

    public static void main(String[] args) throws Exception {

        args = new String[]{"d:/zz.txt","d:/out"};

        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);

        //自定分区
        job.setPartitionerClass(MyPartitoner.class);
        job.setNumReduceTasks(2);

        job.setJarByClass(WordCountDriver.class);

        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReduce.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);


        Path path = new Path(args[0]);
        FileInputFormat.setInputPaths(job, path);
        FileOutputFormat.setOutputPath(job,new Path(args[1]));

        boolean b = job.waitForCompletion(true);

        System.exit(b ? 0 : 1);

    }

}
